package two;

public abstract class AbstractExpression {
    protected int num1;
    protected int num2;
    protected int result;

    public AbstractExpression(int num1, int num2) {
        this.num1 = num1;
        this.num2 = num2;
        this.result = calculate(); // 构造时计算结果
    }

    // 抽象计算方法，子类实现
    public abstract int calculate();

    // 抽象格式化方法，子类实现运算符
    public abstract String toString();

    public int getResult() {
        return result;
    }
}